/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.base.controller;

import com.xy.biz.base.client.BizCodeClient;
import com.xy.biz.base.domain.req.GetBizCodeRequest;
import com.xy.biz.base.service.BizCodeService;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.annotation.Validatable;
import com.xy.tool.context.UserContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 *
 * @author zsp
 * @date 2020-8-25
 */
@Slf4j
@Api(tags = "业务编码")
@RestController
@RequestMapping("/api/base/biz_code")
public class BizCodeController implements BizCodeClient {

    @Autowired
    private BizCodeService bizCodeService;

    @Validatable
    @Override
    public Result<String> nextBizCode(@RequestBody GetBizCodeRequest request) {
        return bizCodeService.getBizCode(request.getCode(), UserContextHolder.getTenantId());
    }

    @Validatable
    @ApiOperation("获取一个业务编码")
    @PostMapping("/get")
    public Result<String> getBizCode(@RequestBody GetBizCodeRequest request) {
        return bizCodeService.getBizCode(request.getCode(), UserContextHolder.getTenantId());
    }

}
